/**
 * 作者:hanbo
 * 日期:2018/11/2215:20
 * 描述:屏幕工具类
 */

export class Screen {
    /**
     * 获取屏幕每英寸像素点数
     * @returns {any[]} 两个方向的DPI
     */
    static getDPI() {
        let arrDPI = new Array();
        if (window.screen.deviceXDPI != undefined) {
            arrDPI[0] = window.screen.deviceXDPI;
            arrDPI[1] = window.screen.deviceYDPI;
        }
        else {
            let tmpNode = document.createElement("DIV");
            tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
            document.body.appendChild(tmpNode);
            console.log(tmpNode.offsetWidth);
            arrDPI[0] = parseInt(tmpNode.offsetWidth);
            arrDPI[1] = parseInt(tmpNode.offsetHeight);
            tmpNode.parentNode.removeChild(tmpNode);
        }
        return arrDPI;
    }

    /**
     * 获取1m上有多少像素点
     * @returns {number} 像素点数
     */
    static getDPM(){
        let tmpNode = document.createElement("DIV");
        tmpNode.style.cssText = "width:100cm;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
        document.body.appendChild(tmpNode);
        let result = parseInt(tmpNode.offsetWidth);
        tmpNode.parentNode.removeChild(tmpNode);
        return result;
    }
}